//
//  TestBViewController.swift
//  Demo
//
//  Created by yuyang on 2021/11/25.
//

import Foundation
import UIKit
import YangRouter

extension TestBViewController: RouterRegisterProtocol {
    static func registerName() -> String {
        return "TestBViewController"
    }

    func pageWillPushAppearReceive(params: [String: Any]?, options: [String: Any]?) {
        print("")
    }

    func pageWillPopToAppearReceive(params: [String: Any]?, options: [String: Any]?) {
        print("")
    }
}

class TestBViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .white

        let pushCButton = UIButton(type: .custom)
        pushCButton.backgroundColor = .blue
        pushCButton.setTitle("pushCButton", for: .normal)
        view.addSubview(pushCButton)

        pushCButton.frame = CGRect(x: 10, y: 100, width: 200, height: 50)
        pushCButton.addTarget(self, action: #selector(pushC), for: .touchUpInside)

        let popButton = UIButton(type: .custom)
        popButton.backgroundColor = .red
        popButton.setTitle("popButton", for: .normal)
        view.addSubview(popButton)

        popButton.frame = CGRect(x: 10, y: 200, width: 200, height: 50)
        popButton.addTarget(self, action: #selector(popBack), for: .touchUpInside)

        let replaceToCButton = UIButton(type: .custom)
        replaceToCButton.backgroundColor = .gray
        replaceToCButton.setTitle("replaceToCButton", for: .normal)
        view.addSubview(replaceToCButton)

        replaceToCButton.frame = CGRect(x: 10, y: 300, width: 200, height: 50)
        replaceToCButton.addTarget(self, action: #selector(replaceToC), for: .touchUpInside)
    }

    @objc func pushC() {
        Router.pushPage("TestCViewController", params: ["from": "B", "to": "C"], options: ["animated": false])
    }

    @objc func popBack() {
        Router.popPage(options: ["animated": false])
    }

    @objc func replaceToC() {
        Router.replacePage("TestCViewController", params: ["from": "B", "replace": "C"], options: ["animated": true])
    }

}
